<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<h1>JavaScript Example 10</h1>
<br>
Shows how define and call custom function - factorial (recursive version)
<br>
<hr>
<br>

<!-- SCRIPT STARTS HERE -->

<script type="text/javascript">
	// define function
	function factorial(x) {
		return x==1?1:factorial(x-1)*x;
	}
	// declare variable and read it from popup dialog
	var n = window.prompt("Enter a (small) number:");
	// calculate result, invoke function
	document.writeln("The result is: " + factorial(n));

</script>

<!-- SCRIPT ENDS HERE -->

</body>
</html>
